<?php
class business_ctl_admin_pleasebalance extends desktop_controller{
    public function __construct($app)
	{
		parent::__construct($app);
         $this->app_b2c = app::get('b2c');
        $this->router = app::get('desktop')->router();
		header("cache-control: no-store, no-cache, must-revalidate");
	}
	
    public function index(){
        $this->finder('business_mdl_pleasebalance',array(

            'title'=>app::get('business')->_('申请结算单'),'allow_detail_popup'=>true,
           // 'base_filter'=>array('refund_type'=>2),
            'actions'=>array(

                        ),
            'use_buildin_export'=>true,
            'use_buildin_set_tag'=>true,
          //  'use_buildin_recycle'=>false,
            'use_buildin_filter'=>true,
            'use_view_tab'=>true,
            'force_view_tab'=>true,
            ));
    }

    public function _views(){

		$count_all = app::get('business')->model('pleasebalance')->count(array(1=>1));
		$count_balance = app::get('business')->model('pleasebalance')->count(array('status'=>'succ'));
		$count_no_balance = app::get('business')->model('pleasebalance')->count(array('status'=>'ready'));

        return array(
                0=>array('label'=>app::get('ectools')->_('全部'),'optional'=>false,'filter'=>'','addon'=>$count_all,'href'=>$this->router->gen_url(array('app'=>'business','ctl'=>'admin_pleasebalance','act'=>'index','view'=>0))),
                1=>array('label'=>app::get('ectools')->_('申请中'),'optional'=>false,'filter'=>array('status'=>'ready'),'addon'=>$count_no_balance,'href'=>$this->router->gen_url(array('app'=>'business','ctl'=>'admin_pleasebalance','act'=>'index','view'=>1))),
                2=>array('label'=>app::get('ectools')->_('结算成功'),'optional'=>false,'filter'=>array('status'=>'succ'),'addon'=>$count_balance,'href'=>$this->router->gen_url(array('app'=>'business','ctl'=>'admin_pleasebalance','act'=>'index','view'=>2))),
            );
    }
    function toupdate(){
        $this->pagedata['pb_id']=$_GET['pb_id'];
        $p_balance=app::get('business')->model('pleasebalance');
        $list=$p_balance->dump($_GET['pb_id'],'*',array(':storemanger' => array('*')));
        $obj_account = app::get('pam')->model('account');
        $uname = $obj_account->getRow('login_name',array('account_id'=>$list['storemanger']['account_id']));
        $list['account']=$uname['login_name'];
       
        $list['t_begin']=date('Y-m-d h:m:s',$list['t_begin']);
        $this->pagedata['list']=$list;
  
        $this->display('admin/mome.html');
    }
    function pleaseupdate(){
        $this->begin();

         $p_balance=app::get('business')->model('pleasebalance');
         $list=$p_balance->dump(array('pb_id'=>$_POST['pb_id']));

         $op_name=(!$this->user->user_id) ? app::get('b2c')->_('管理员') : $this->user->user_data['name'];
         $t_end=time();

       
         if($p_balance->update(array('people'=>$op_name,'t_payed'=>$t_end,'mome'=>$_POST['mome'],'status'=>'succ'),array('pb_id' =>$list['pb_id']))){

             $reund_ids=explode('|',$list['bigstr']);
            
             $refunds = app::get('ectools')->model('refunds');

             $refunds->update(array('status'=>'succ','t_payed'=>time()),array('refund_id|in'=>$reund_ids));
             $this->end(true, '结算成功！');
         }else{
             $this->end(false, '结算失败！');
         }
    }

    
}